package com.xmut.mall.store.controller;

import com.xmut.mall.store.annotation.CheckJwt;
import com.xmut.mall.store.dto.StoreSearchParams;
import com.xmut.mall.store.service.StoreInfoService;
import com.xmut.mall.store.utils.RespBean;
import com.xmut.mall.store.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("store/storeinfo")
public class StoreInfoController {

    @Autowired
    private StoreInfoService storeInfoService;

    /**
     * 获取商城店铺列表分页数据
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getStoreByPage")
    public RespBean getStoreByPage(@RequestBody StoreSearchParams params){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(params,vo);
        return storeInfoService.getStoreByPage(vo,params);
    }

    /**
     * 获取卖家店铺详情
     * @param storeId
     * @return
     */
    @GetMapping("/getStoreDetail/{storeId}")
    public RespBean getStoreDetail(@PathVariable Long storeId){
        return storeInfoService.getStoreDetail(storeId);
    }

    /**
     * 检测当前用户是否申请过店铺
     * @param memberId
     * @return
     */
    @CheckJwt
    @GetMapping("/checkUserStoreExists/{memberId}")
    public RespBean checkUserStoreExists(@PathVariable Long memberId){
        return storeInfoService.checkUserStoreExists(memberId);
    }

    /**
     * 根据params参数获取商铺审核的分页数据
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getShopAuditPageByParams")
    public RespBean getShopAuditPageByParams(@RequestBody Map<String,Object> params){
        return storeInfoService.getShopAuditPageByParams(params);
    }

    /**
     * 根据用户id获取商铺信息
     * @param memberId
     * @return
     */
    @PostMapping("/getShopStatusByMemberId/{memberId}")
    public RespBean getShopStatusByMemberId(@PathVariable Long memberId){
        return storeInfoService.getShopStatusByMemberId(memberId);
    }

    /**
     * 根据用户Id获取该用户的店铺信息
     * @param memberId
     * @return
     */
    @CheckJwt
    @GetMapping("/getStoreInfoByMemberId/{memberId}")
    public RespBean getStoreInfoByMemberId(@PathVariable Long memberId){
        return storeInfoService.getStoreInfoByMemberId(memberId);
    }
}
